package de.augsburg.chris.hausino.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import de.augsburg.chris.hausino.entity.Person;


@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class PersonDAO {
	
	@PersistenceContext(unitName = "hausino")
    EntityManager em;
	
	
	public List<Person> getAll() {
		CriteriaBuilder cBuilder = em.getCriteriaBuilder();
		CriteriaQuery<Person> pQuery = cBuilder.createQuery(Person.class);
		Root<Person> p = pQuery.from(Person.class);
		pQuery.select(p);
		TypedQuery<Person> query = em.createQuery(pQuery);
		return query.getResultList();
	}
	
	public void persist(Person person){
		em.merge(person);
	}
	

}
